﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using CommunityToolkit.Mvvm.Input;
using Zo.ExcelBox.Pages;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using Zo.ExcelBox.Models;
using System.Windows.Forms;
using MiniExcelLibs;
using System.Windows.Shapes;
using System.Drawing.Printing;
using Zo.ExcelBox.Base;
using SqlSugar;
using HandyControl.Controls;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Zo.ExcelBox.ViewModels
{
    /// <summary>
    /// 数据转换
    /// </summary>
    public partial class DataTransformVM : ObservableObject
    {

        /// <summary>
        /// 树形数据
        /// </summary>

        public ObservableCollection<DataTransformTree> TreeDatas { get; set; } = new ObservableCollection<DataTransformTree>();


        /// <summary>
        /// 传值
        /// </summary>
        ObservableCollection<DataTransformFolder> DataTransformFolders = null;



        /// <summary>
        /// 解析后的数据
        /// </summary>
        ObservableCollection<JudicialCaseTransactionRecord> _records = new ObservableCollection<JudicialCaseTransactionRecord>();

        /// <summary>
        /// 必须这样写
        /// </summary>
        public ObservableCollection<JudicialCaseTransactionRecord> Records
        {
            get => _records;
            set => SetProperty(ref _records, value);
        }


        /// <summary>
        /// 案件信息
        /// </summary>
        public ObservableCollection<JudicialCase> judicialCases = new ObservableCollection<JudicialCase>();


        /// <summary>
        /// 案件信息
        /// </summary>
        public ObservableCollection<JudicialCase> JudicialCases
        {
            get => judicialCases;
            set => SetProperty(ref judicialCases, value);
        }


        public JudicialCase _selectJudicialCase;

        public JudicialCase SelectJudicialCase
        {
            get => _selectJudicialCase;
            set => SetProperty(ref _selectJudicialCase, value);
        }


        private int _pageIndex = 1;
        /// <summary>
        /// 当前页
        /// </summary>
        public int PageIndex
        {
            get => _pageIndex;
            set => SetProperty(ref _pageIndex, value);
        }

        private int _pageSize = 20;
        /// <summary>
        /// 每页的数据量
        /// </summary>
        public int PageSize
        {
            get => _pageSize;
            set => SetProperty(ref _pageSize, value);
        }

        private int _maxPageCount = 0;

        /// <summary>
        /// 最大页数
        /// </summary>
        public int MaxPageCount
        {
            get => _maxPageCount;
            set => SetProperty(ref _maxPageCount, value);
        }


        private int _dataCount = 0;

        /// <summary>
        /// 数据总数量
        /// </summary>
        public int DataCount
        {
            get => _dataCount;
            set => SetProperty(ref _dataCount, value);
        }




        /// <summary>
        /// 交易户名
        /// </summary> 
        public string _accountName = string.Empty;

        /// <summary>
        /// 交易户名
        /// </summary> 
        public string AccountName
        {
            get => _accountName;
            set => SetProperty(ref _accountName, value);
        }

        /// <summary>
        /// 对手账号
        /// </summary>
        public string _counterpartyAccount = string.Empty;


        /// <summary>
        /// 对手账号
        /// </summary> 
        public string CounterpartyAccount
        {
            get => _counterpartyAccount;
            set => SetProperty(ref _counterpartyAccount, value);
        }

        /// <summary>
        /// 交易卡号
        /// </summary>

        public string _cardNumber = string.Empty;

        /// <summary>
        /// 交易卡号
        /// </summary> 
        public string CardNumber
        {
            get => _cardNumber;
            set => SetProperty(ref _cardNumber, value);
        }

        /// <summary>
        /// 对手卡号
        /// </summary>
        public string _counterpartyCardNumber = string.Empty;


        /// <summary>
        /// 对手卡号
        /// </summary> 
        public string CounterpartyCardNumber
        {
            get => _counterpartyCardNumber;
            set => SetProperty(ref _counterpartyCardNumber, value);
        }

        /// <summary>
        /// 查询最小金额
        /// </summary>
        public decimal _TransactionAmount0 = 0;
        public decimal TransactionAmount0
        {
            get => _TransactionAmount0;
            set => SetProperty(ref _TransactionAmount0, value);
        }

        /// <summary>
        /// 查询最大金额
        /// </summary>
        public decimal _TransactionAmount1 = 0;
        public decimal TransactionAmount1
        {
            get => _TransactionAmount1;
            set => SetProperty(ref _TransactionAmount1, value);
        }

        /// <summary>
        /// 交易时间 开始
        /// </summary>
        public DateTime? _transactionTime0 = null;

        /// <summary>
        /// 交易时间 开始
        /// </summary> 
        public DateTime? TransactionTime0
        {
            get => _transactionTime0;
            set => SetProperty(ref _transactionTime0, value);
        }



        /// <summary>
        /// 交易时间 结束
        /// </summary>
        public DateTime? _transactionTime1 = null;

        /// <summary>
        /// 交易时间 结束
        /// </summary> 
        public DateTime? TransactionTime1
        {
            get => _transactionTime1;
            set => SetProperty(ref _transactionTime1, value);
        }


        /// <summary>
        /// 打开设置
        /// </summary>
        public IRelayCommand OnOpenSettingCommand { get; }

        /// <summary>
        /// 合并数据
        /// </summary>
        public IRelayCommand OnMergingDataCommand { get; }

        /// <summary>
        /// 分页改变
        /// </summary>
        public IRelayCommand<int> OnPageChangeCommand { get; }


        /// <summary>
        /// 提交数据
        /// </summary>
        public IRelayCommand OnSubmitCommand { get; }


        /// <summary>
        /// 提交数据
        /// </summary>
        public IRelayCommand OnSearchCommand { get; }

        /// <summary>
        /// 导出表格
        /// </summary>
        public IRelayCommand OnExportExcelCommand { get; }

        /// <summary>
        /// 数据访问
        /// </summary>
        public static SqlSugarClient _db;


        /// <summary>
        /// 数据转换
        /// </summary>
        public DataTransformVM()
        {
            OnOpenSettingCommand = new RelayCommand(OpenSetting);
            OnMergingDataCommand = new RelayCommand(OnMergingData);
            OnPageChangeCommand = new RelayCommand<int>(OnPageChange);
            OnSubmitCommand = new RelayCommand(OnSubmit);
            OnSearchCommand = new RelayCommand(OnSearch);
            OnExportExcelCommand = new RelayCommand(OnExportExcel);
            _db = new DbContext().DataBase;

            OnInit();
        }


        void OnInit()
        {
            var judicialCases = _db.Queryable<JudicialCase>().ToList() ?? new List<JudicialCase>();
            JudicialCases = new ObservableCollection<JudicialCase>(judicialCases);

            if (judicialCases.Count > 0)
            {
                SelectJudicialCase = judicialCases[0];
            }

        }

        /// <summary>
        /// 打开设置
        /// </summary>
        void OpenSetting()
        {

            var win = new DataTransformFolderSetWin(DataTransformFolders);

            win.OnSucceed += (data) =>
            {
                DataTransformFolders = data;
                CreateFolderNodes(data);
            };

            win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            win.Owner = System.Windows.Application.Current.MainWindow;
            win.ShowDialog();
        }


        void CreateFolderNodes(ObservableCollection<DataTransformFolder> datas)
        {
            foreach (var data in datas)
            {
                TreeDatas.Add(CreateFolderNode(data));
            }
        }

        string[] allowedExtensions = new[] { ".xls", ".xlsx", ".csv" };

        private DataTransformTree CreateFolderNode(DataTransformFolder data)
        {

            var folderPath = data.FolderPath;

            var dirInfo = new DirectoryInfo(folderPath);
            var folderItem = new DataTransformTree
            {
                FileName = dirInfo.Name,
                IsFile = false,
                FilePath = folderPath,
            };

            var fileInfos = dirInfo.GetFiles()
                .Where(f => allowedExtensions.Contains(f.Extension.ToLower()))
                .ToArray();
            try
            {

                // 添加该文件夹下的文件
                foreach (var file in fileInfos)
                {
                    var m1 = new DataTransformTree
                    {
                        FileName = file.Name,
                        FilePath = file.FullName,
                        Info = file,
                        SelectMapTemplate = data.SelectMapTemplate
                    };
                    folderItem.Children.Add(m1);
                }
            }
            catch
            {
                // 忽略无法访问的文件夹
            }

            return folderItem;
        }


        //零时
        List<JudicialCaseTransactionRecord> tempRecords = new List<JudicialCaseTransactionRecord>();

        /// <summary>
        /// 合并数据
        /// </summary>
        public void OnMergingData()
        {

            var trees = TreeDatas.SelectMany(s => s.Children).ToList();

            foreach (DataTransformTree tree in trees)
            {
                if (tree.IsFile)
                {
                    ReadExcel(tree);
                }
            }

            LoadData();
        }

        /// <summary>
        /// 读取execl文件内容
        /// </summary>
        /// <param name="data"></param>
        void ReadExcel(DataTransformTree data)
        {

            var extension = System.IO.Path.GetExtension(data.FilePath).ToLower();

            var excelType = ExcelType.UNKNOWN;
            MiniExcelLibs.Configuration config = null;

            switch (extension)
            {
                case ".csv":
                    excelType = ExcelType.CSV;
                    config = new MiniExcelLibs.Csv.CsvConfiguration()
                    {
                        StreamReaderFunc = (stream) => new StreamReader(stream, Encoding.GetEncoding("gb2312"))
                    };
                    break;
                case ".xls":
                    excelType = ExcelType.XLSX;
                    break;
                case ".xlsx":
                    excelType = ExcelType.XLSX;
                    break;
            }


            if (data.SelectMapTemplate == TemplateType.BankCard)
            {
                var rows = MiniExcel.Query<JudicialCaseTransactionRecord_BankCard>(data.FilePath, excelType: excelType, configuration: config);
                foreach (var item in rows)
                {
                    tempRecords.Add(new JudicialCaseTransactionRecord
                    {
                        AccountType = "银行卡",
                        Type = JudicialCaseTransactionRecord_Type.BankCard,
                        AccountBalance = item.AccountBalance,
                        AccountName = item.AccountName ?? string.Empty,
                        MAC = item.MAC ?? string.Empty,
                        TransactionAmount = item.TransactionAmount,
                        BankName = item.BankName ?? string.Empty,
                        BranchCode = item.BranchCode ?? string.Empty,
                        CardNumber = item.CardNumber ?? string.Empty,
                        CashFlag = item.CashFlag ?? string.Empty,
                        CounterpartyBank = item.CounterpartyBank ?? string.Empty,
                        CounterpartyCardNumber = item.CounterpartyCardNumber ?? string.Empty,
                        CounterpartyIdNumber = item.CounterpartyIdNumber ?? string.Empty,
                        CounterpartyName = item.CounterpartyName ?? string.Empty,
                        Currency = item.Currency ?? string.Empty,
                        IP = item.IP ?? string.Empty,
                        Remarks = item.Remarks ?? string.Empty,
                        SuccessFlag = item.SuccessFlag ?? string.Empty,
                        Summary = item.Summary ?? string.Empty,
                        TransactionDirection = item.TransactionDirection ?? string.Empty,
                        TransactionLocation = item.TransactionLocation ?? string.Empty,
                        TransactionId = item.TransactionId ?? string.Empty,
                        TransactionTime = item.TransactionTime,
                        TransactionType = item.TransactionType ?? string.Empty
                    });
                }

            }
            else if (data.SelectMapTemplate == TemplateType.WeChat)
            {
                var rows = MiniExcel.Query<JudicialCaseTransactionRecord_WeChat>(data.FilePath, excelType: excelType, configuration: config);

                foreach (var item in rows)
                {
                    tempRecords.Add(new JudicialCaseTransactionRecord
                    {
                        AccountType = "微信",
                        AccountNumber = item.AccountNumber ?? string.Empty,
                        Type = JudicialCaseTransactionRecord_Type.WeChat,
                        AccountBalance = item.AccountBalance,
                        MAC = item.MAC ?? string.Empty,
                        TransactionAmount = item.TransactionAmount,
                        BankName = item.BankName ?? string.Empty,
                        CardNumber = item.CardNumber ?? string.Empty,
                        CashFlag = item.CashFlag ?? string.Empty,
                        CounterpartyBank = item.CounterpartyBank ?? string.Empty,
                        CounterpartyCardNumber = item.CounterpartyCardNumber ?? string.Empty,
                        CounterpartyName = item.CounterpartyName ?? string.Empty,
                        Currency = item.Currency ?? string.Empty,
                        IP = item.IP ?? string.Empty,
                        TransactionDirection = item.TransactionDirection ?? string.Empty,
                        TransactionLocationLat = item.TransactionLocationLat ?? string.Empty,
                        TransactionLocationLong = item.TransactionLocationLong ?? string.Empty,
                        TransactionId = item.TransactionId ?? string.Empty,
                        TransactionTime = item.TransactionTime,
                        TransactionType = item.TransactionType ?? string.Empty
                    });
                }
            }
            else if (data.SelectMapTemplate == TemplateType.AliPay)
            {
                var rows = MiniExcel.Query<JudicialCaseTransactionRecord_AliPay>(data.FilePath, excelType: excelType, configuration: config);
                foreach (var item in rows)
                {
                    tempRecords.Add(new JudicialCaseTransactionRecord
                    {
                        AccountType = "支付宝",
                        AccountNumber=item.AccountNumber ?? string.Empty,
                        Type = JudicialCaseTransactionRecord_Type.AliPay,
                        AccountBalance = item.AccountBalance,
                        MAC = item.MAC ?? string.Empty,
                        TransactionAmount = item.TransactionAmount,
                        BankName = item.BankName ?? string.Empty,
                        CardNumber = item.CardNumber ?? string.Empty,
                        CashFlag = item.CashFlag ?? string.Empty,
                        CounterpartyBank = item.CounterpartyBank ?? string.Empty,
                        CounterpartyCardNumber = item.CounterpartyCardNumber ?? string.Empty,
                        CounterpartyName = item.CounterpartyName ?? string.Empty,
                        Currency = item.Currency ?? string.Empty,
                        IP = item.IP ?? string.Empty,
                        TransactionDirection = item.TransactionDirection ?? string.Empty,
                        TransactionLocationLat = item.TransactionLocationLat ?? string.Empty,
                        TransactionLocationLong = item.TransactionLocationLong ?? string.Empty,
                        TransactionId = item.TransactionId ?? string.Empty,
                        TransactionTime = item.TransactionTime,
                        TransactionType = item.TransactionType ?? string.Empty
                    });
                }

            }
            //else if (data.SelectMapTemplate == TemplateType.EiBankCard)
            //{
            //    var rows = MiniExcel.Query<JudicialCaseTransactionRecord_EiBankCard>(data.FilePath, excelType: excelType, configuration: config);
            //    foreach (var item in rows)
            //    {
            //        tempRecords.Add(new JudicialCaseTransactionRecord
            //        {
            //            AccountBalance = item.AccountBalance,
            //            AccountName = item.AccountName,
            //            AccountNumber = item.AccountNumber,
            //            AccountType = item.AccountType,
            //            CounterpartyAccount = item.CounterpartyAccount,
            //            CounterpartyInternalAccount = item.CounterpartyInternalAccount,
            //            InternalAccount = item.InternalAccount,
            //            MAC = item.MAC,
            //            TransactionAmount = item.TransactionAmount,
            //            BankName = item.BankName,
            //            BranchCode = item.BranchCode,
            //            BranchName = item.BranchName,
            //            CardNumber = item.CardNumber,
            //            CashFlag = item.CashFlag,
            //            CounterpartyBalance = item.CounterpartyBalance,
            //            CounterpartyBank = item.CounterpartyBank,
            //            CounterpartyCardNumber = item.CounterpartyCardNumber,
            //            CounterpartyIdNumber = item.CounterpartyIdNumber,
            //            CounterpartyName = item.CounterpartyName,
            //            Currency = item.Currency,
            //            IdNumber = item.IdNumber,
            //            IP = item.IP,
            //            Remarks = item.Remarks,
            //            ReversalFlag = item.ReversalFlag,
            //            SourceFileName = item.SourceFileName,
            //            SuccessFlag = item.SuccessFlag,
            //            Summary = item.Summary,
            //            TransactionDirection = item.TransactionDirection,
            //            TransactionLocation = item.TransactionLocation,
            //            TransactionLocationLat = item.TransactionLocationLat,
            //            TransactionLocationLong = item.TransactionLocationLong,
            //            TransactionId = item.TransactionId,
            //            TransactionTime = item.TransactionTime,
            //            TransactionType = item.TransactionType
            //        });
            //    }

            //}
            //else if (data.SelectMapTemplate == TemplateType.AliPay129)
            //{
            //    var rows = MiniExcel.Query<JudicialCaseTransactionRecord_129AliPay>(data.FilePath, excelType: excelType, configuration: config);
            //    foreach (var item in rows)
            //    {
            //        tempRecords.Add(new JudicialCaseTransactionRecord
            //        {
            //            AccountBalance = item.AccountBalance,
            //            AccountName = item.AccountName,
            //            AccountNumber = item.AccountNumber,
            //            AccountType = item.AccountType,
            //            CounterpartyAccount = item.CounterpartyAccount,
            //            CounterpartyInternalAccount = item.CounterpartyInternalAccount,
            //            InternalAccount = item.InternalAccount,
            //            MAC = item.MAC,
            //            TransactionAmount = item.TransactionAmount,
            //            BankName = item.BankName,
            //            BranchCode = item.BranchCode,
            //            BranchName = item.BranchName,
            //            CardNumber = item.CardNumber,
            //            CashFlag = item.CashFlag,
            //            CounterpartyBalance = item.CounterpartyBalance,
            //            CounterpartyBank = item.CounterpartyBank,
            //            CounterpartyCardNumber = item.CounterpartyCardNumber,
            //            CounterpartyIdNumber = item.CounterpartyIdNumber,
            //            CounterpartyName = item.CounterpartyName,
            //            Currency = item.Currency,
            //            IdNumber = item.IdNumber,
            //            IP = item.IP,
            //            Remarks = item.Remarks,
            //            ReversalFlag = item.ReversalFlag,
            //            SourceFileName = item.SourceFileName,
            //            SuccessFlag = item.SuccessFlag,
            //            Summary = item.Summary,
            //            TransactionDirection = item.TransactionDirection,
            //            TransactionLocation = item.TransactionLocation,
            //            TransactionLocationLat = item.TransactionLocationLat,
            //            TransactionLocationLong = item.TransactionLocationLong,
            //            TransactionId = item.TransactionId,
            //            TransactionTime = item.TransactionTime,
            //            TransactionType = item.TransactionType
            //        });
            //    }

            //}
            //else if (data.SelectMapTemplate == TemplateType.WeChat129)
            //{
            //    var rows = MiniExcel.Query<JudicialCaseTransactionRecord_129AliPay>(data.FilePath, excelType: excelType, configuration: config);
            //    foreach (var item in rows)
            //    {
            //        tempRecords.Add(new JudicialCaseTransactionRecord
            //        {
            //            AccountBalance = item.AccountBalance,
            //            AccountName = item.AccountName,
            //            AccountNumber = item.AccountNumber,
            //            AccountType = item.AccountType,
            //            CounterpartyAccount = item.CounterpartyAccount,
            //            CounterpartyInternalAccount = item.CounterpartyInternalAccount,
            //            InternalAccount = item.InternalAccount,
            //            MAC = item.MAC,
            //            TransactionAmount = item.TransactionAmount,
            //            BankName = item.BankName,
            //            BranchCode = item.BranchCode,
            //            BranchName = item.BranchName,
            //            CardNumber = item.CardNumber,
            //            CashFlag = item.CashFlag,
            //            CounterpartyBalance = item.CounterpartyBalance,
            //            CounterpartyBank = item.CounterpartyBank,
            //            CounterpartyCardNumber = item.CounterpartyCardNumber,
            //            CounterpartyIdNumber = item.CounterpartyIdNumber,
            //            CounterpartyName = item.CounterpartyName,
            //            Currency = item.Currency,
            //            IdNumber = item.IdNumber,
            //            IP = item.IP,
            //            Remarks = item.Remarks,
            //            ReversalFlag = item.ReversalFlag,
            //            SourceFileName = item.SourceFileName,
            //            SuccessFlag = item.SuccessFlag,
            //            Summary = item.Summary,
            //            TransactionDirection = item.TransactionDirection,
            //            TransactionLocation = item.TransactionLocation,
            //            TransactionLocationLat = item.TransactionLocationLat,
            //            TransactionLocationLong = item.TransactionLocationLong,
            //            TransactionId = item.TransactionId,
            //            TransactionTime = item.TransactionTime,
            //            TransactionType = item.TransactionType
            //        });
            //    }
            //}
        }


        List<JudicialCaseTransactionRecord> Rows = new List<JudicialCaseTransactionRecord>();

        /// <summary>
        /// 加载数据
        /// </summary>
        void LoadData(int page = 1)
        {
            var query = tempRecords.Skip((page - 1) * PageSize).Take(PageSize);

            if (!string.IsNullOrWhiteSpace(AccountName))
            {
                query = query.Where(w => w.AccountName.Contains(AccountName));
            }

            if (!string.IsNullOrWhiteSpace(CounterpartyAccount))
            {
                query = query.Where(w => w.CounterpartyAccount.Contains(CounterpartyAccount));
            }

            if (!string.IsNullOrWhiteSpace(CardNumber))
            {
                query = query.Where(w => w.CardNumber.Contains(CardNumber));
            }

            if (!string.IsNullOrWhiteSpace(CounterpartyCardNumber))
            {
                query = query.Where(w => w.CounterpartyCardNumber.Contains(CounterpartyCardNumber));
            }

            if (TransactionAmount0 >0)
            {
                query = query.Where(w => w.TransactionAmount >= TransactionAmount0);
            }

            if (TransactionAmount1 > 0)
            {
                query = query.Where(w => w.TransactionAmount <= TransactionAmount1);
            }

            if (TransactionTime0 != null)
            {
                query = query.Where(w => w.TransactionTime.Date >= TransactionTime0.Value.Date);
            }

            if (TransactionTime1 != null)
            {
                query = query.Where(w => w.TransactionTime.Date <= TransactionTime1.Value.Date);
            }
            Rows = query.ToList();

            DataCount = tempRecords.Count;
            MaxPageCount = CommonHelper.CalculateTotalPages(tempRecords.Count, PageSize);

            Records = new ObservableCollection<JudicialCaseTransactionRecord>(Rows);
        }


        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="page"></param>
        void OnPageChange(int page)
        {
            LoadData(page);
        }

        /// <summary>
        /// 搜索
        /// </summary>
        void OnSearch()
        {
            LoadData(1);
        }


        /// <summary>
        /// 保存到案件数据库中去
        /// </summary>
        void OnSubmit()
        {

            if (tempRecords.Count <= 0)
            {
                HandyControl.Controls.MessageBox.Show("请先导入数据");
                return;
            }

            if (SelectJudicialCase == null)
            {
                HandyControl.Controls.MessageBox.Show("请选中一个案件");
                return;
            }

            tempRecords.ForEach(item =>
            {
                item.JudicialCase_Id = SelectJudicialCase.Id;
            });

            var row = _db.Insertable(tempRecords).ExecuteCommand();
            if (row > 0)
            {
                Growl.Success("保存成功");
            }
            else
            {
                HandyControl.Controls.MessageBox.Show("保存失败");
            }
        }

        /// <summary>
        /// 导出表格
        /// </summary>
        void OnExportExcel()
        {

            if (Rows.Count <= 0) 
            {
                HandyControl.Controls.MessageBox.Show("无数据可以导出");
                return;
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                Title = "保存 Excel 文件",
                Filter = "Excel 文件 (*.xlsx)|*.xlsx",
                FileName = $"{SelectJudicialCase.Name}_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx"
            };


            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = saveFileDialog.FileName;
                try
                {
                    // 写入 Excel 文件
                    MiniExcel.SaveAs(filePath, Rows);
                    HandyControl.Controls.MessageBox.Show("导出成功！", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception ex)
                {
                    HandyControl.Controls.MessageBox.Show($"导出失败：{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
    }




    /// <summary>
    /// 菜单数据
    /// </summary>
    public class DataTransformTree : ObservableObject
    {

        /// <summary>
        /// 文件名
        /// </summary>
        public string FileName { get; set; }

        /// <summary>
        /// 文件物理目录
        /// </summary>
        public string FilePath { get; set; }

        /// <summary>
        /// 文件完整信息
        /// </summary>
        public FileInfo Info { get; set; }


        /// <summary>
        /// 数据转换模板
        /// </summary>
        public TemplateType SelectMapTemplate { get; set; }


        /// <summary>
        /// 是否是文件
        /// </summary>
        public bool IsFile { get; set; } = true;

        public bool IsExpanded { get; set; } = true; // 默认展开

        /// <summary>
        /// 
        /// </summary>
        public ObservableCollection<DataTransformTree> Children { get; set; } = new ObservableCollection<DataTransformTree>();
    }
}
